﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YiDa.Infrastructure
{
    /// <summary>
    /// DisposableObject类型
    /// </summary>
    public abstract class DisposableObject : IDisposable
    {   
        /// <summary>
        /// 析构比数时不进行真正的析构,要依赖.Net的自动析构或者显示析构
        /// </summary>
        ~DisposableObject()
        {
            this.Dispose(false);
        }

        /// <summary>
        /// 子类要重写析构方法
        /// </summary>
        /// <param name="disposing"></param>
        protected abstract void Dispose(bool disposing);

        protected void ExplicitDispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        #region IDisposable Members

        /// <summary>
        /// 执行析构释放资源
        /// </summary>
        public void Dispose()
        {
            this.ExplicitDispose();
        }

        #endregion
    }
}
